package com.zjut.zs.userstatus.action;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zjut.an.admin.dao.AnAdmin;
import com.zjut.an.log.dao.AnLog;
import com.zjut.an.log.manager.AnLogManager;
import com.zjut.an.util.module.PageModule;
import com.zjut.an.util.system.Status;
import com.zjut.an.util.tools.DateUtil;
import com.zjut.an.util.tools.JSONUtilClass;
import com.zjut.an.util.tools.JSONUtilClassTime;
import com.zjut.an.util.tools.MD5;
import com.zjut.an.util.tools.StringUtil;
import com.zjut.common.codec.DesUtils;
import com.zjut.common.idgen.IdGenerate;
import com.zjut.zs.applyview.dao.ZsApplyView;
import com.zjut.zs.applyview.manager.ZsApplyViewManager;
import com.zjut.zs.school.dao.ZsSchool;
import com.zjut.zs.school.manager.ZsSchoolManager;
import com.zjut.zs.user.dao.ZsUser;
import com.zjut.zs.user.manager.ZsUserManager;
import com.zjut.zs.userstatus.dao.ZsUserStatus;
import com.zjut.zs.userstatus.manager.ZsUserStatusManager;
import com.zjut.zs.util.tools.ZsHTMLCreat;

public class ZsUserStatusAction extends ActionSupport implements
ServletResponseAware, ServletRequestAware, ModelDriven<ZsUserStatus>{

	private HttpServletRequest request;
	private HttpServletResponse response;
	private HttpSession session;
	
	private ZsUserStatus obj;
	private Map<String , Object> dataMap;
	private int offset = 0, limit = 10;
	private String order;
	private String sort;
	private String search;
	private String rowstr;
	
	@Resource(name = "ZsUserStatusManager")
	private ZsUserStatusManager manager;
	
	@Resource(name = "ZsUserManager")
	private ZsUserManager umanager;

	@Resource(name = "ZsApplyViewManager")
	private ZsApplyViewManager amanager;

	@Resource(name = "AnLogManager")
	private AnLogManager logmanager;

	@Resource(name = "ZsSchoolManager")
	private ZsSchoolManager scmanager;

	@Resource(name = "IdGenerate")
	private IdGenerate idgenerate;
	
	@Resource(name = "StringUtil")
	private StringUtil stringutil;
	
	@Resource(name = "DateUtil")
	private DateUtil dateutil;

	@Resource(name = "ZsHTMLCreat")
	private ZsHTMLCreat html;
	
	public String zsUserStatusList() {
		try {
			request.setCharacterEncoding("UTF-8");
			dataMap = new HashMap<String, Object>();
			int pageNumber = offset/limit + 1;
			PageModule module = manager.getDataByInstance(pageNumber, limit, sort, order, obj);
			dataMap.put("rows", module.getObjects());
			dataMap.put("total", module.getTotal()); 
			obj = null; 
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	public String zsUserStatusCount() {
		try {
			request.setCharacterEncoding("UTF-8");
			dataMap = new HashMap<String, Object>();
			int count = manager.getCountByInstance(obj);
			dataMap.put("total", count); 
			obj = null; 
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	@SuppressWarnings("unchecked")
	public String zsUserStatusDeletes() {
		try {
			String objumniJSON = rowstr;
			manager.deleteDatas(JSONUtilClass.getDTOList(objumniJSON, ZsUserStatus.class));
			dataMap = new HashMap<String, Object>();
			dataMap.put("flag", "success");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	public String zsUserStatusDelete() {
		try {
			String objumniJSON = rowstr;
			manager.deleteData((ZsUserStatus)JSONUtilClass.getDTO(objumniJSON, ZsUserStatus.class));
			dataMap = new HashMap<String, Object>();
			dataMap.put("flag", "success");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	public String zsUserStatusUpdate() {
		try {
			String objumniJSON = rowstr;
			manager.updateData((ZsUserStatus)JSONUtilClass.getDTO(objumniJSON, ZsUserStatus.class));
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	public String zsUserStatusSave() {
		obj = (ZsUserStatus)(JSONUtilClass.getDTOArray(rowstr, ZsUserStatus.class)[0]);
		if (!stringutil.isEmpty(obj.getUssId())) {
			//-------update-------
			manager.updateData(obj);
		} else {
			//-------insert-------
			obj.setUssId(idgenerate.nextId());
			manager.addData(obj);
		}
		rowstr = null;
		return SUCCESS;
	}

	public String zsUserStatusEmsSave() {
		try {
			System.out.println("############"+JSONUtilClass.getMapFromJson(rowstr).get("emsNum").toString());
			String emsNum = JSONUtilClass.getMapFromJson(rowstr).get("emsNum").toString();
			String ussId = JSONUtilClass.getMapFromJson(rowstr).get("ussId").toString();
			obj = manager.getData(ussId);
			obj.setEmsNum(emsNum);
			manager.updateData(obj);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusAppPublic() throws UnsupportedEncodingException {//用户个人确认材料
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			ZsSchool school = new ZsSchool();
			school = (ZsSchool)scmanager.getDataByInstance(1,1,null,null,school).getObjects().get(0);
			String usId = request.getParameter("usId");
			String key = request.getParameter("key");
			ZsUser user = umanager.getData(usId);
			manager.updatefileStatus(user);
			obj.setZsUser(umanager.getData(usId));
			obj = (ZsUserStatus)manager.getDataByInstance(1, 1, null, null, obj).getObjects().get(0);

			/**如果系统确认材料仍然开放，或者用户允许延迟提交材料，则可以确认材料**/
			//System.out.println("@@@@"+MD5.toMD5(usId.toString()).equals(key) + Status.ON.getStatus().equals(school.getScBackActive())+Status.APPSTATUS_NOTIME.getStatus().equals(obj.getAppStatus()));
			//System.out.println("@@@@"+obj.getFileStatus());
			if(MD5.toMD5(usId.toString()).equals(key) && (Status.ON.getStatus().equals(school.getScAppActive())||Status.APPSTATUS_NOTIME.getStatus().equals(obj.getAppStatus())  )) {
				//如果已经上传或者没有填写专项
				if (Status.FILESTATUS_YES.getStatus().equals(obj.getFileStatus())) {
					manager.appStatus(obj, Status.APPSTATUS_YES.getStatus());
					manager.updateData(obj);
					AnLog log = new AnLog("报考日志",logmanager.subIdcard(((ZsUser)session.getAttribute("zsUser")).getUsIdcard())+Status.APPSTATUS_YES.getStatus()+logmanager.subIdcard(obj.getUsIdcard())+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
					logmanager.addData(log);
					dataMap.put("flag", "success");		
				} else {
					dataMap.put("flag", "error");
				}
			}else{
				dataMap.put("flag", "error");
			}			
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String zsUserStatusApp() throws UnsupportedEncodingException {//批量操作
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
			for (ZsApplyView av : avs) {
				obj = manager.getData(av.getUssId());				
				manager.appStatus(obj, request.getParameter("appStatus"));
				if(Status.APPSTATUS_NO.getStatus().equals(request.getParameter("appStatus")) || Status.APPSTATUS_NOTIME.getStatus().equals(request.getParameter("appStatus")) ) {
					obj.setMessage(obj.getMessage()+"<br>"+dateutil.getCurrentDate5()+"材料确认被管理员退回，请修改后重新确认");
				}
				manager.updateData(obj);
				AnLog log = new AnLog(obj.getZsUser().getUsId(), "报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("appStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
			}		
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	@SuppressWarnings("unchecked")
	public String zsUserStatusAppAll() throws UnsupportedEncodingException {//批量操作
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		if (session.getAttribute("admin")!=null) {//只有管理员才允许执行该操作，以免信息泄露
			try {
				List<ZsUserStatus> list = manager.getDatas();
				for(ZsUserStatus obj:list) {
					manager.appStatus(obj, request.getParameter("appStatus"));
					manager.updateData(obj);
					AnLog log = new AnLog(obj.getZsUser().getUsId(), "报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("appStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
					logmanager.addData(log);
				}	
				dataMap.put("flag", "success");
			} catch (Exception e) {
				e.printStackTrace();
				dataMap.put("flag", "error");
			}
			obj = null; 
		}		
		return SUCCESS;
	}
	@SuppressWarnings("unchecked")
	public String zsUserStatusSendBack() throws UnsupportedEncodingException {//用户个人申请退回申请表
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			ZsSchool school = new ZsSchool();
			school = (ZsSchool)scmanager.getDataByInstance(1,1,null,null,school).getObjects().get(0);

			String usId = request.getParameter("usId");
			String key = request.getParameter("key");
			if(MD5.toMD5(usId.toString()).equals(key)&&Status.ON.getStatus().equals(school.getScBackActive())) {
				obj.setZsUser(umanager.getData(usId));
				obj = (ZsUserStatus)manager.getDataByInstance(1, 1, null, null, obj).getObjects().get(0);
				manager.sendStatus(obj, Status.SENDSTATUS_BACK.getStatus());				
				manager.updateData(obj);
				//obj.setMessage(html.getInputString(obj.getMessage())+"<br>"+dateutil.getCurrentDate5()+"申请撤回，原因："+request.getParameter("message").toString()+"。");
				obj.setMessage(dateutil.getCurrentDate5()+"申请撤回提交，原因："+request.getParameter("message").toString()+"。");
				manager.updateData(obj);
				AnLog log = new AnLog(usId,"报考日志",logmanager.subIdcard(((ZsUser)session.getAttribute("zsUser")).getUsIdcard())+Status.SENDSTATUS_BACK.getStatus()+logmanager.subIdcard(obj.getUsIdcard())+"于"+dateutil.getCurrentDate5()+"原因："+request.getParameter("message").toString(), dateutil.getCurrentDate5());
				logmanager.addData(log);
				dataMap.put("flag", "success");
			}else{
				dataMap.put("flag", "error");
			}
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	@SuppressWarnings("unchecked")
	public String zsUserAppSendBack() throws UnsupportedEncodingException {//用户个人撤回材料确认
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			ZsSchool school = new ZsSchool();
			school = (ZsSchool)scmanager.getDataByInstance(1,1,null,null,school).getObjects().get(0);

			String usId = request.getParameter("usId");
			String key = request.getParameter("key");
			if(MD5.toMD5(usId.toString()).equals(key)&&Status.ON.getStatus().equals(school.getScBackActive())) {
				obj.setZsUser(umanager.getData(usId));
				obj = (ZsUserStatus)manager.getDataByInstance(1, 1, null, null, obj).getObjects().get(0);
				manager.appStatus(obj, Status.APPSTATUS_BACK.getStatus());				
				manager.updateData(obj);
				//obj.setMessage(html.getInputString(obj.getMessage())+"<br>"+dateutil.getCurrentDate5()+"申请撤回，原因："+request.getParameter("message").toString()+"。");
				obj.setMessage(dateutil.getCurrentDate5()+"申请撤回材料确认，原因："+request.getParameter("message").toString()+"。");
				manager.updateData(obj);
				AnLog log = new AnLog(usId,"报考日志",logmanager.subIdcard(((ZsUser)session.getAttribute("zsUser")).getUsIdcard())+Status.APPSTATUS_BACK.getStatus()+logmanager.subIdcard(obj.getUsIdcard())+"于"+dateutil.getCurrentDate5()+"原因："+request.getParameter("message").toString(), dateutil.getCurrentDate5());
				logmanager.addData(log);
				dataMap.put("flag", "success");
			}else{
				dataMap.put("flag", "error");
			}
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	@SuppressWarnings("unchecked")
	public String zsUserStatusSend() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("checkStatusType"))) {//单页初审
				String ussId = request.getParameter("ussId");
				obj = manager.getData(ussId);
				manager.sendStatus(obj, request.getParameter("sendStatus"));
				manager.updateData(obj);
				AnLog log = new AnLog(obj.getZsUser().getUsId(), "报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("sendStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
			} else {
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					manager.sendStatus(obj, request.getParameter("sendStatus"));
					manager.updateData(obj);
					AnLog log = new AnLog(obj.getZsUser().getUsId(), "报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("sendStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
					logmanager.addData(log);
				}
			}			
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	public String zsUserPrintPublic() throws UnsupportedEncodingException {//用户个人提交准考证打印
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			String ussId = request.getParameter("ussId");
			String key = request.getParameter("key");
			if(MD5.toMD5(ussId.toString()).equals(key)) {
				obj = manager.getData(ussId);
				obj.setPrintStatus(Status.PRINTSTATUS_YES.getStatus());
				obj.setPrintTime(dateutil.getCurrentDate5());
				manager.updateData(obj);
				AnLog log = new AnLog("报考日志",logmanager.subIdcard(((ZsUser)session.getAttribute("zsUser")).getUsIdcard())+Status.PRINTSTATUS_YES.getStatus()+logmanager.subIdcard(obj.getUsIdcard())+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
				dataMap.put("flag", "success");
			}else{
				dataMap.put("flag", "error");
			}
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		return SUCCESS;
	}
	@SuppressWarnings("unchecked")
	public String zsUserStatusSendPublic() throws UnsupportedEncodingException {//用户个人提交申请
		/*
		 * request.setCharacterEncoding("UTF-8"); String objumniJSON = rowstr; dataMap =
		 * new HashMap<String, Object>(); try { ZsSchool school = new ZsSchool(); school
		 * =
		 * (ZsSchool)scmanager.getDataByInstance(1,1,null,null,school).getObjects().get(
		 * 0);
		 * 
		 * String usId = request.getParameter("usId"); String key =
		 * request.getParameter("key");
		 * if(MD5.toMD5(usId.toString()).equals(key)&&Status.ON.getStatus().equals(
		 * school.getScAppActive())) { obj.setZsUser(umanager.getData(usId)); String
		 * message = amanager.checkSend(umanager.getData(usId)); if
		 * (message.trim().length()>0) { dataMap.put("flag", "error"); } else { obj =
		 * (ZsUserStatus)manager.getDataByInstance(1, 1, null, null,
		 * obj).getObjects().get(0); manager.sendStatus(obj,
		 * Status.SENDSTATUS_YES.getStatus()); manager.updateData(obj); AnLog log = new
		 * AnLog(usId,"报考日志",logmanager.subIdcard(((ZsUser)session.getAttribute("zsUser"
		 * )).getUsIdcard())+Status.SENDSTATUS_YES.getStatus()+logmanager.subIdcard(obj.
		 * getUsIdcard())+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
		 * logmanager.addData(log); dataMap.put("flag", "success"); } }else{
		 * dataMap.put("flag", "error"); } } catch (Exception e) { e.printStackTrace();
		 * dataMap.put("flag", "error"); } obj = null;
		 */
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String zsUserStatusCheck() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("checkStatusType"))) {//单页初审
				String ussId = request.getParameter("ussId");
				obj = manager.getData(ussId);
				manager.checkStatus(obj, request.getParameter("checkStatus"));
				manager.updateData(obj);
				AnLog log = new AnLog(obj.getZsUser().getUsId(),"报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("checkStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
			} else {
				System.out.println(rowstr);
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);				
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					manager.checkStatus(obj, request.getParameter("checkStatus"));
					manager.updateData(obj);
					AnLog log = new AnLog(obj.getZsUser().getUsId(),"报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("checkStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
					logmanager.addData(log);
				}
			}	
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusPass() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
			for (ZsApplyView av : avs) {
				obj = manager.getData(av.getUssId());				
				manager.passStatus(obj, request.getParameter("passStatus"));
				manager.updateData(obj);
				System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%"+((AnAdmin)session.getAttribute("admin")).getAccount());
				AnLog log = new AnLog("报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("passStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
			}
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusLocal() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("localStatusType"))) {//扫二维码签到
				String ussId = request.getParameter("ussId");
				obj = manager.getData(ussId);
				obj.setLocalStatus(Status.LOCALSTATUS_YES.getStatus());
				manager.updateData(obj);
				dataMap.put("flag", "success");				
			} else {
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());	
					obj.setLocalStatus(request.getParameter("localStatus"));
					manager.updateData(obj);
				}
				dataMap.put("flag", "success");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusPay() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("payStatusType"))) {//扫二维码缴费
				String ussId = request.getParameter("ussId");
				obj = manager.getData(ussId);
				obj.setPayStatus(Status.PAYSTATUS_YES.getStatus());
				obj.setPassTime(dateutil.getCurrentDate5());				
				manager.updateData(obj);
				dataMap.put("flag", "success");				
			} else {
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					obj.setPayStatus(request.getParameter("payStatus"));
					obj.setPayTime(dateutil.getCurrentDate5());
					manager.updateData(obj);
				}
				dataMap.put("flag", "success");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusExId() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			int exId = Integer.parseInt(request.getParameter("exId"));
			List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
			for (ZsApplyView av : avs) {
				obj = manager.getData(av.getUssId());				
				obj.setExId(exId);
				manager.updateData(obj);
			}
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusTag() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("tagStatusType"))) {//单个设置
				String ussId = request.getParameter("ussId");
				String tag = request.getParameter("tag");
				obj = manager.getData(ussId);
				obj.setScColumn2(tag);
				manager.updateData(obj);
			} else {
				String tag = request.getParameter("tag");
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					obj.setScColumn2(tag);
					manager.updateData(obj);
				}
			}			
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusFileCheck() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("fileCheckStatusType"))) {//单页初审
				String ussId = request.getParameter("ussId");
				String fileCheckStatus = request.getParameter("fileCheckStatus");
				obj = manager.getData(ussId);
				obj.setFileCheckStatus(fileCheckStatus);
				obj.setFileTime(dateutil.getCurrentDate5());
				manager.updateData(obj);
				AnLog log = new AnLog("报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("fileCheckStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
				logmanager.addData(log);
			} else {
				String fileCheckStatus = request.getParameter("fileCheckStatus");
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					obj.setFileCheckStatus(fileCheckStatus);
					obj.setFileTime(dateutil.getCurrentDate5());
					manager.updateData(obj);
					AnLog log = new AnLog("报考日志",((AnAdmin)session.getAttribute("admin")).getAccount()+"对"+logmanager.subIdcard(obj.getUsIdcard())+"执行"+request.getParameter("fileCheckStatus")+"于"+dateutil.getCurrentDate5(), dateutil.getCurrentDate5());
					logmanager.addData(log);
				}
				dataMap.put("flag", "success");
			}			
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}

	public String zsUserStatusSetNum() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		dataMap = new HashMap<String, Object>();		
		try {
			if ("usIdcard".equals(JSONUtilClass.getMapFromJson(rowstr).get("editStatusType"))) {//修改身份证
				System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%"+rowstr);
				obj = (ZsUserStatus)JSONUtilClass.getDTO(rowstr, ZsUserStatus.class);
				ZsUserStatus status = manager.getData(obj.getUssId());
				status.setUsIdcard(JSONUtilClass.getMapFromJson(rowstr).get("usIdcard").toString());
				//status.setUsIdcard(DesUtils.encode(JSONUtilClass.getMapFromJson(rowstr).get("usIdcard").toString(), "s,w,y"));
				manager.updateData(status);
				ZsUser user = umanager.getData(JSONUtilClass.getMapFromJson(rowstr).get("usId").toString());
				user.setUsIdcard(JSONUtilClass.getMapFromJson(rowstr).get("usIdcard").toString());
				//user.setUsIdcard(DesUtils.encode(JSONUtilClass.getMapFromJson(rowstr).get("usIdcard").toString(),"s,w,y"));
				umanager.updateData(user);
			} else {
				obj = (ZsUserStatus)JSONUtilClass.getDTO(rowstr, ZsUserStatus.class);
				ZsUserStatus status = manager.getData(obj.getUssId());
				if(!isEmpty(obj.getTestNo()))status.setTestNo(obj.getTestNo());
				if(!isEmpty(obj.getTestBnum()))status.setTestBnum(obj.getTestBnum());
				if(!isEmpty(obj.getTestMnum()))status.setTestMnum(obj.getTestMnum());
				if(!isEmpty(obj.getTestNum()))status.setTestNum(obj.getTestNum());
				if(!isEmpty(obj.getMessage()))status.setMessage(obj.getMessage());
				//if(!isEmpty(obj.getScColumn1()))status.setScColumn1(obj.getScColumn1());
				//if(!isEmpty(obj.getScColumn2()))status.setScColumn2(obj.getScColumn2());
				manager.updateData(status);
			}		
			dataMap.put("flag", "success");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
			return ERROR;
		}		
	}

	private boolean isEmpty(String value) {
		if (value==null || value.trim().length()==0) {
			return true;
		}
		return false;
	}
	
	public String zsUserStatusSetScColumn1() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		dataMap = new HashMap<String, Object>();
		//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%"+rowstr);
		try {
			obj = (ZsUserStatus)JSONUtilClass.getDTO(rowstr, ZsUserStatus.class);
			ZsUserStatus status = manager.getData(obj.getUssId());
			status.setScColumn1(obj.getScColumn1());
			manager.updateData(status);
			dataMap.put("flag", "success");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
			return ERROR;
		}		
	}

	@SuppressWarnings("unchecked")
	public String zsUserStatusEms() throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		String objumniJSON = rowstr;
		dataMap = new HashMap<String, Object>();
		try {
			if ("single".equals(request.getParameter("emsStatusType"))) {//扫二维码缴费
				String ussId = request.getParameter("ussId");
				obj = manager.getData(ussId);
				obj.setEmsStatus(Status.EMSSTATUS_YES.getStatus());
				obj.setEmsTime(dateutil.getCurrentDate5());				
				manager.updateData(obj);		
			} else {
				//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%"+request.getParameter("emsStatus"));
				List<ZsApplyView> avs = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
				for (ZsApplyView av : avs) {
					obj = manager.getData(av.getUssId());				
					obj.setEmsStatus(request.getParameter("emsStatus"));
					obj.setEmsTime(dateutil.getCurrentDate5());
					manager.updateData(obj);
				}
			}
			dataMap.put("flag", "success");
		} catch (Exception e) {
			e.printStackTrace();
			dataMap.put("flag", "error");
		}
		obj = null; 
		return SUCCESS;
	}
	
	public String zsUserStatus() {
		try {
			request.setCharacterEncoding("UTF-8");
			dataMap = new HashMap<String, Object>();
			String ussId = request.getParameter("ussId");
			obj = manager.getData(ussId);
			dataMap.put("rows", obj);
			obj = null;
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	@Override
	public ZsUserStatus getModel() {
		if (null == obj) {
			obj = new ZsUserStatus();
		}
		return obj;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;
		session = request.getSession();
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		response = arg0;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public ZsUserStatus getAl() {
		return obj;
	}

	public void setAl(ZsUserStatus obj) {
		this.obj = obj;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public String getRowstr() {
		return rowstr;
	}

	public void setRowstr(String rowstr) {
		this.rowstr = rowstr;
	}

	public ZsUserStatusManager getManager() {
		return manager;
	}

	public void setManager(ZsUserStatusManager manager) {
		this.manager = manager;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

}
